import axios from 'axios';
import type{ AxiosInstance } from 'axios';

// import axiosTauriApiAdapter from 'axios-tauri-api-adapter';
import { adapter as axiosTauriApiAdapter } from '@/tauri-plugins/axios-adapter';
// eslint-disable-next-line import/no-cycle
import { initAxiosClientInterceptors } from './interceptors';

const reqTimeout = 10 * 1000;
const clientTauri = axios.create({
  adapter: axiosTauriApiAdapter,
  timeout: reqTimeout,
});
export const clientWeb = axios.create({
  timeout: reqTimeout,
});

// web 时使用默认的客户端实例 若处于 TAURI 客户端模式时 单独适配
let client: AxiosInstance;
if (window.__TAURI_IPC__) {
  client = clientTauri;
} else {
  client = clientWeb;
}
initAxiosClientInterceptors(client);

export { client, axios };
